package com.woniuxy.thred.state;

/**
 * description: BlockedSleep03 <br>
 * date: 2022/2/5 5:40 下午 <br>
 * author: shesaifei <br>
 * version: 1.0 <br>
 */

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * sleep模拟倒计时1
 */
public class BlockedSleep03 {
    public static void main(String[] args) throws InterruptedException {
        //System.currentTimeMillis() 返回现在的时间
        //现在的时间
        Date endTime = new Date(System.currentTimeMillis() + 1000 * 10);
        long end = endTime.getTime();
        while (true) {
            String format = new SimpleDateFormat("mm:ss").format(endTime);
            System.out.println(format);
            Thread.sleep(1000);
            //endTime=现在的时间-要倒计时的时间
            endTime = new Date(endTime.getTime() - 1000);
            if (end - 10000 > endTime.getTime()) {
                break;
            }
        }
    }

    public static void test() throws InterruptedException {
        //倒数10个数，1秒一个
        int num = 10;
        while (true) {
            Thread.sleep(1000);
            System.out.println(num--);
        }
    }
}
